﻿using System;

class IndexOfElementBiggerThanNeighbours

            // Write a method that returns the index of the first element in array that is bigger than its neighbors, or -1, if there’s no such element.
            // Use the method from the previous exercise.

{
     public static int sign = 0;
 
    public static int ValidPosition(int[] elements, int position)
    {
        if (position + 1 < elements.Length && position - 1 >= 0)
        {
            return 1;
        }
        else if (position + 1 == elements.Length)
        {
            return 2;
        }
        else
        {
            return 3;
        }
    }
 
    public static bool BiggerCheck(int[] elements, int position)
    {
        sign = ValidPosition(elements, position);
        if (sign == 1 && elements[position] > elements[position - 1] && elements[position] > elements[position + 1])
        {
            return true;
        }
        else if (sign == 2 && elements[position] > elements[position - 1])
        {
            return true;
        }
        else if (sign == 3 && elements[position] > elements[position + 1])
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    static void Main()
    {
        Console.Write("Enter the length of the array: ");
        int arraySize = int.Parse(Console.ReadLine());
        int[] array = new int[arraySize];
        Console.WriteLine();

        Console.WriteLine("Enter the elements of the array:");
        for (int i = 0; i < arraySize; i++)
        {
            array[i] = int.Parse(Console.ReadLine());
        }
        Console.WriteLine();

        Console.Write("Enter the position you wish to check: ");
        int position = int.Parse(Console.ReadLine());
        bool checkBool = BiggerCheck(array, position);
        Console.WriteLine("The element at position {0} is {1}", position, array[position]);
        if (sign == 1)
        {
            Console.WriteLine("{0} is bigger than {1} and {2} : {3}", array[position], array[position - 1], array[position + 1], checkBool);
        }
        else if (sign == 2)
        {
            Console.WriteLine("{0} is bigger than {1} and (empty) : {2}", array[position], array[position - 1], checkBool);
        }
        else if (sign == 3)
        {
            Console.WriteLine("{0} is bigger than (empty) and {1} : {2}", array[position], array[position + 1], checkBool);
        }
    }
}

